<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - ged.info - gil/algorithm.hpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../index.html">directory</a> - <a href="index.html">gil</a> - algorithm.hpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>ged.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-06-09</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">14</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">92.9 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">13</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : /*
<span class="lineNum">       2 </span>                :     Copyright 2005-2007 Adobe Systems Incorporated
<span class="lineNum">       3 </span>                :    
<span class="lineNum">       4 </span>                :     Use, modification and distribution are subject to the Boost Software License,
<span class="lineNum">       5 </span>                :     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       6 </span>                :     http://www.boost.org/LICENSE_1_0.txt).
<span class="lineNum">       7 </span>                : 
<span class="lineNum">       8 </span>                :     See http://opensource.adobe.com/gil for most recent version including documentation.
<span class="lineNum">       9 </span>                : */
<span class="lineNum">      10 </span>                : 
<span class="lineNum">      11 </span>                : 
<span class="lineNum">      12 </span>                : /*************************************************************************************************/
<span class="lineNum">      13 </span>                : 
<span class="lineNum">      14 </span>                : #ifndef GIL_ALGORITHM_HPP
<span class="lineNum">      15 </span>                : #define GIL_ALGORITHM_HPP
<span class="lineNum">      16 </span>                : 
<span class="lineNum">      17 </span>                : #include &lt;cassert&gt;
<span class="lineNum">      18 </span>                : #include &lt;cstddef&gt;
<span class="lineNum">      19 </span>                : #include &lt;cstring&gt;
<span class="lineNum">      20 </span>                : #include &lt;algorithm&gt;
<span class="lineNum">      21 </span>                : #include &lt;iterator&gt;
<span class="lineNum">      22 </span>                : #include &lt;memory&gt;
<span class="lineNum">      23 </span>                : #include &lt;typeinfo&gt;
<span class="lineNum">      24 </span>                : #include &quot;gil_config.hpp&quot;
<span class="lineNum">      25 </span>                : #include &quot;gil_concept.hpp&quot;
<span class="lineNum">      26 </span>                : #include &quot;color_base_algorithm.hpp&quot;
<span class="lineNum">      27 </span>                : #include &quot;image_view.hpp&quot;
<span class="lineNum">      28 </span>                : #include &quot;image_view_factory.hpp&quot;
<span class="lineNum">      29 </span>                : #include &quot;bit_aligned_pixel_iterator.hpp&quot;
<span class="lineNum">      30 </span>                : 
<span class="lineNum">      31 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      32 </span>                : /// \file               
<span class="lineNum">      33 </span>                : /// \brief Some basic STL-style algorithms when applied to image views
<span class="lineNum">      34 </span>                : /// \author Lubomir Bourdev and Hailin Jin \n
<span class="lineNum">      35 </span>                : ///         Adobe Systems Incorporated
<span class="lineNum">      36 </span>                : /// \date   2005-2008 \n Last updated on March 12, 2008
<span class="lineNum">      37 </span>                : ///
<span class="lineNum">      38 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      39 </span>                : 
<span class="lineNum">      40 </span>                : //#ifdef _MSC_VER
<span class="lineNum">      41 </span>                : //#pragma warning(push)
<span class="lineNum">      42 </span>                : //#pragma warning(disable : 4244)     // conversion from 'gil::image&lt;V,Alloc&gt;::coord_t' to 'int', possible loss of data (visual studio compiler doesn't realize that the two types are the same)
<span class="lineNum">      43 </span>                : //#endif
<span class="lineNum">      44 </span>                : 
<span class="lineNum">      45 </span>                : namespace boost { namespace gil {
<span class="lineNum">      46 </span>                : 
<span class="lineNum">      47 </span>                : //forward declarations
<span class="lineNum">      48 </span>                : template &lt;typename ChannelPtr, typename ColorSpace&gt;
<span class="lineNum">      49 </span>                : struct planar_pixel_iterator;
<span class="lineNum">      50 </span>                : template &lt;typename Iterator&gt;
<span class="lineNum">      51 </span>                : class memory_based_step_iterator;
<span class="lineNum">      52 </span>                : template &lt;typename StepIterator&gt;
<span class="lineNum">      53 </span>                : class memory_based_2d_locator;
<span class="lineNum">      54 </span>                : 
<span class="lineNum">      55 </span>                : // a tag denoting incompatible arguments
<span class="lineNum">      56 </span>                : struct error_t {};
<span class="lineNum">      57 </span>                : 
<span class="lineNum">      58 </span>                : /// \defgroup ImageViewSTLAlgorithms STL-like Algorithms
<span class="lineNum">      59 </span>                : /// \ingroup ImageViewAlgorithm
<span class="lineNum">      60 </span>                : /// \brief Image view-equivalents of STL algorithms
<span class="lineNum">      61 </span>                : ///
<span class="lineNum">      62 </span>                : /// Image views provide 1D iteration of their pixels via \p begin() and \p end() methods,
<span class="lineNum">      63 </span>                : /// which makes it possible to use STL algorithms with them. However, using nested loops
<span class="lineNum">      64 </span>                : /// over X and Y is in many cases more efficient. The algorithms in this section resemble
<span class="lineNum">      65 </span>                : /// STL algorithms, but they abstract away the nested loops and take views (as opposed to ranges) as input.
<span class="lineNum">      66 </span>                : ///
<span class="lineNum">      67 </span>                : /// Most algorithms check whether the image views are 1D-traversable. A 1D-traversable image view has no gaps
<span class="lineNum">      68 </span>                : /// at the end of the rows. In other words, if an x_iterator of that view is advanced past the last pixel in a row
<span class="lineNum">      69 </span>                : /// it will move to the first pixel of the next row. When image views are 1D-traversable, the algorithms use
<span class="lineNum">      70 </span>                : /// a single loop and run more efficiently. If one or more of the input views are not 1D-traversable, the algorithms
<span class="lineNum">      71 </span>                : /// fall-back to an X-loop nested inside a Y-loop.
<span class="lineNum">      72 </span>                : ///
<span class="lineNum">      73 </span>                : /// The algorithms typically delegate the work to their corresponding STL algorithms. For example, \p copy_pixels calls
<span class="lineNum">      74 </span>                : /// \p std::copy either for each row, or, when the images are 1D-traversable, once for all pixels.
<span class="lineNum">      75 </span>                : ///
<span class="lineNum">      76 </span>                : /// In addition, overloads are sometimes provided for the STL algorithms. For example, std::copy for planar iterators
<span class="lineNum">      77 </span>                : /// is overloaded to perform \p std::copy for each of the planes. \p std::copy over bitwise-copiable pixels results in
<span class="lineNum">      78 </span>                : /// std::copy over unsigned char, which STL typically implements via \p memmove.
<span class="lineNum">      79 </span>                : ///
<span class="lineNum">      80 </span>                : /// As a result \p copy_pixels may result in a single call to \p memmove for interleaved 1D-traversable views, 
<span class="lineNum">      81 </span>                : /// or one per each plane of planar 1D-traversable views, or one per each row of interleaved non-1D-traversable images, etc.
<span class="lineNum">      82 </span>                : 
<span class="lineNum">      83 </span>                : 
<span class="lineNum">      84 </span>                : /// \defgroup STLOptimizations  Performance overloads of STL algorithms
<span class="lineNum">      85 </span>                : /// \ingroup ImageViewAlgorithm
<span class="lineNum">      86 </span>                : /// \brief overloads of STL algorithms allowing more efficient implementation when used with GIL constructs
<span class="lineNum">      87 </span>                : 
<span class="lineNum">      88 </span>                : /// \brief A generic binary operation on views
<span class="lineNum">      89 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">      90 </span>                : ///
<span class="lineNum">      91 </span>                : /// Use this class as a convenience superclass when defining an operation for any image views.
<span class="lineNum">      92 </span>                : /// Many operations have different behavior when the two views are compatible. This class checks
<span class="lineNum">      93 </span>                : /// for compatibility and invokes apply_compatible(V1,V2) or apply_incompatible(V1,V2) of the subclass.
<span class="lineNum">      94 </span>                : /// You must provide apply_compatible(V1,V2) method in your subclass, but apply_incompatible(V1,V2)
<span class="lineNum">      95 </span>                : /// is not required and the default throws std::bad_cast.
<span class="lineNum">      96 </span>                : template &lt;typename Derived, typename Result=void&gt;
<span class="lineNum">      97 </span>                : struct binary_operation_obj {
<span class="lineNum">      98 </span>                :     typedef Result result_type;
<span class="lineNum">      99 </span>                : 
<span class="lineNum">     100 </span>                :     template &lt;typename V1, typename V2&gt; GIL_FORCEINLINE
<span class="lineNum">     101 </span>                :     result_type operator()(const std::pair&lt;const V1*,const V2*&gt;&amp; p) const {
<span class="lineNum">     102 </span>                :         return apply(*p.first, *p.second, typename views_are_compatible&lt;V1,V2&gt;::type());
<span class="lineNum">     103 </span>                :     }
<span class="lineNum">     104 </span>                : 
<span class="lineNum">     105 </span>                :     template &lt;typename V1, typename V2&gt; GIL_FORCEINLINE
<span class="lineNum">     106 </span>                :     result_type operator()(const V1&amp; v1, const V2&amp; v2) const {
<span class="lineNum">     107 </span>                :         return apply(v1, v2, typename views_are_compatible&lt;V1,V2&gt;::type());
<span class="lineNum">     108 </span>                :     }
<span class="lineNum">     109 </span>                : 
<span class="lineNum">     110 </span>                :     result_type operator()(const error_t&amp;) const { throw std::bad_cast(); }
<span class="lineNum">     111 </span>                : private:
<span class="lineNum">     112 </span>                : 
<span class="lineNum">     113 </span>                :     // dispatch from apply overload to a function with distinct name
<span class="lineNum">     114 </span>                :     template &lt;typename V1, typename V2&gt;
<span class="lineNum">     115 </span>                :     GIL_FORCEINLINE result_type apply(const V1&amp; v1, const V2&amp; v2, mpl::false_) const {
<span class="lineNum">     116 </span>                :         return ((const Derived*)this)-&gt;apply_incompatible(v1,v2);
<span class="lineNum">     117 </span>                :     }
<span class="lineNum">     118 </span>                : 
<span class="lineNum">     119 </span>                :     // dispatch from apply overload to a function with distinct name
<span class="lineNum">     120 </span>                :     template &lt;typename V1, typename V2&gt;
<span class="lineNum">     121 </span>                :     GIL_FORCEINLINE result_type apply(const V1&amp; v1, const V2&amp; v2, mpl::true_) const {
<span class="lineNum">     122 </span>                :         return ((const Derived*)this)-&gt;apply_compatible(v1,v2);
<span class="lineNum">     123 </span>                :     }
<span class="lineNum">     124 </span>                : 
<span class="lineNum">     125 </span>                :     // function with distinct name - it can be overloaded by subclasses
<span class="lineNum">     126 </span>                :     template &lt;typename V1, typename V2&gt;
<span class="lineNum">     127 </span>                :     GIL_FORCEINLINE result_type apply_incompatible(const V1&amp; v1, const V2&amp; v2) const {
<span class="lineNum">     128 </span>                :         throw std::bad_cast();
<span class="lineNum">     129 </span>                :     }
<span class="lineNum">     130 </span>                : };
<span class="lineNum">     131 </span>                : } }  // namespace boost::gil
<span class="lineNum">     132 </span>                : 
<span class="lineNum">     133 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     134 </span>                : ///
<span class="lineNum">     135 </span>                : /// std::copy and gil::copy_pixels
<span class="lineNum">     136 </span>                : ///
<span class="lineNum">     137 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     138 </span>                : 
<span class="lineNum">     139 </span>                : /// \defgroup ImageViewSTLAlgorithmsCopyPixels copy_pixels
<span class="lineNum">     140 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     141 </span>                : /// \brief std::copy for image views
<span class="lineNum">     142 </span>                : 
<span class="lineNum">     143 </span>                : namespace std {
<span class="lineNum">     144 </span>                : 
<span class="lineNum">     145 </span>                : /// \ingroup STLOptimizations
<span class="lineNum">     146 </span>                : /// \brief Copy when both src and dst are interleaved and of the same type can be just memmove
<span class="lineNum">     147 </span>                : template&lt;typename T, typename Cs&gt; 
<span class="lineNum">     148 </span>                : GIL_FORCEINLINE boost::gil::pixel&lt;T,Cs&gt;* 
<span class="lineNum">     149 </span>                : copy(boost::gil::pixel&lt;T,Cs&gt;* first, boost::gil::pixel&lt;T,Cs&gt;* last, 
<span class="lineNum">     150 </span>                :      boost::gil::pixel&lt;T,Cs&gt;* dst) { 
<span class="lineNum">     151 </span>                :     return (boost::gil::pixel&lt;T,Cs&gt;*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
<span class="lineNum">     152 </span>                : }
<span class="lineNum">     153 </span>                : 
<span class="lineNum">     154 </span>                : /// \ingroup STLOptimizations
<span class="lineNum">     155 </span>                : /// \brief Copy when both src and dst are interleaved and of the same type can be just memmove
<span class="lineNum">     156 </span>                : template&lt;typename T, typename Cs&gt; 
<span class="lineNum">     157 </span>                : GIL_FORCEINLINE boost::gil::pixel&lt;T,Cs&gt;* 
<span class="lineNum">     158 </span>                : copy(const boost::gil::pixel&lt;T,Cs&gt;* first, const boost::gil::pixel&lt;T,Cs&gt;* last, 
<span class="lineNum">     159 </span>                :      boost::gil::pixel&lt;T,Cs&gt;* dst) { 
<span class="lineNum">     160 </span>                :     return (boost::gil::pixel&lt;T,Cs&gt;*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
<span class="lineNum">     161 </span>                : }
<span class="lineNum">     162 </span>                : } // namespace std
<span class="lineNum">     163 </span>                : 
<span class="lineNum">     164 </span>                : namespace boost { namespace gil {
<span class="lineNum">     165 </span>                : namespace detail {
<span class="lineNum">     166 </span>                : template &lt;typename I, typename O&gt; struct copy_fn { 
<span class="lineNum">     167 </span>                :     GIL_FORCEINLINE I operator()(I first, I last, O dst) const { return std::copy(first,last,dst); } 
<span class="lineNum">     168 </span>                : };
<span class="lineNum">     169 </span>                : } // namespace detail
<span class="lineNum">     170 </span>                : } }  // namespace boost::gil
<span class="lineNum">     171 </span>                : 
<span class="lineNum">     172 </span>                : namespace std {
<span class="lineNum">     173 </span>                : /// \ingroup STLOptimizations
<span class="lineNum">     174 </span>                : /// \brief Copy when both src and dst are planar pointers is copy for each channel
<span class="lineNum">     175 </span>                : template&lt;typename Cs, typename IC1, typename IC2&gt; GIL_FORCEINLINE
<span class="lineNum">     176 </span>                : boost::gil::planar_pixel_iterator&lt;IC2,Cs&gt; copy(boost::gil::planar_pixel_iterator&lt;IC1,Cs&gt; first, boost::gil::planar_pixel_iterator&lt;IC1,Cs&gt; last, boost::gil::planar_pixel_iterator&lt;IC2,Cs&gt; dst) { 
<span class="lineNum">     177 </span>                :     boost::gil::gil_function_requires&lt;boost::gil::ChannelsCompatibleConcept&lt;typename std::iterator_traits&lt;IC1&gt;::value_type,typename std::iterator_traits&lt;IC2&gt;::value_type&gt; &gt;();
<span class="lineNum">     178 </span>                :     static_for_each(first,last,dst,boost::gil::detail::copy_fn&lt;IC1,IC2&gt;());
<span class="lineNum">     179 </span>                :     return dst+(last-first);
<span class="lineNum">     180 </span>                : }
<span class="lineNum">     181 </span>                : } // namespace std
<span class="lineNum">     182 </span>                : 
<span class="lineNum">     183 </span>                : namespace boost { namespace gil {
<span class="lineNum">     184 </span>                : namespace detail {
<span class="lineNum">     185 </span>                : /// Does a copy-n. If the inputs contain image iterators, performs a copy at each row using the row iterators
<span class="lineNum">     186 </span>                : /// \ingroup CopyPixels
<span class="lineNum">     187 </span>                : template &lt;typename I, typename O&gt;
<span class="lineNum">     188 </span>                : struct copier_n {
<span class="lineNum">     189 </span>                :     GIL_FORCEINLINE void operator()(I src, typename std::iterator_traits&lt;I&gt;::difference_type n, O dst) const { std::copy(src,src+n, dst); }
<span class="lineNum">     190 </span>                : };
<span class="lineNum">     191 </span>                : 
<span class="lineNum">     192 </span>                : /// Source range is delimited by image iterators
<span class="lineNum">     193 </span>                : template &lt;typename IL, typename O&gt;  // IL Models ConstPixelLocatorConcept, O Models PixelIteratorConcept
<span class="lineNum">     194 </span>                : struct copier_n&lt;iterator_from_2d&lt;IL&gt;,O&gt; {
<span class="lineNum">     195 </span>                :     typedef typename std::iterator_traits&lt;iterator_from_2d&lt;IL&gt; &gt;::difference_type diff_t;
<span class="lineNum">     196 </span>                :     GIL_FORCEINLINE void operator()(iterator_from_2d&lt;IL&gt; src, diff_t n, O dst) const {
<span class="lineNum">     197 </span>                :         gil_function_requires&lt;PixelLocatorConcept&lt;IL&gt; &gt;();
<span class="lineNum">     198 </span>                :         gil_function_requires&lt;MutablePixelIteratorConcept&lt;O&gt; &gt;();
<span class="lineNum">     199 </span>                :         while (n&gt;0) {
<span class="lineNum">     200 </span>                :             typedef typename iterator_from_2d&lt;IL&gt;::difference_type diff_t;
<span class="lineNum">     201 </span>                :             diff_t l=src.width()-src.x_pos();
<span class="lineNum">     202 </span>                :             diff_t numToCopy=(n&lt;l ? n:l);
<span class="lineNum">     203 </span>                :             detail::copy_n(src.x(), numToCopy, dst);
<span class="lineNum">     204 </span>                :             dst+=numToCopy;
<span class="lineNum">     205 </span>                :             src+=numToCopy;
<span class="lineNum">     206 </span>                :             n-=numToCopy;
<span class="lineNum">     207 </span>                :         }
<span class="lineNum">     208 </span>                :     }
<span class="lineNum">     209 </span>                : };
<span class="lineNum">     210 </span>                : 
<span class="lineNum">     211 </span>                : /// Destination range is delimited by image iterators
<span class="lineNum">     212 </span>                : template &lt;typename I, typename OL&gt; // I Models ConstPixelIteratorConcept, OL Models PixelLocatorConcept
<span class="lineNum">     213 </span>                : struct copier_n&lt;I,iterator_from_2d&lt;OL&gt; &gt; {
<span class="lineNum">     214 </span>                :     typedef typename std::iterator_traits&lt;I&gt;::difference_type diff_t;
<span class="lineNum">     215 </span>                :     GIL_FORCEINLINE void operator()(I src, diff_t n, iterator_from_2d&lt;OL&gt; dst) const {
<span class="lineNum">     216 </span>                :         gil_function_requires&lt;PixelIteratorConcept&lt;I&gt; &gt;();
<span class="lineNum">     217 </span>                :         gil_function_requires&lt;MutablePixelLocatorConcept&lt;OL&gt; &gt;();
<span class="lineNum">     218 </span>                :         while (n&gt;0) {
<span class="lineNum">     219 </span>                :             diff_t l=dst.width()-dst.x_pos();
<span class="lineNum">     220 </span>                :             diff_t numToCopy=(n&lt;l ? n:l);
<span class="lineNum">     221 </span>                :             detail::copy_n(src, numToCopy, dst.x());
<span class="lineNum">     222 </span>                :             dst+=numToCopy;
<span class="lineNum">     223 </span>                :             src+=numToCopy;
<span class="lineNum">     224 </span>                :             n-=numToCopy;
<span class="lineNum">     225 </span>                :         }
<span class="lineNum">     226 </span>                :     }
<span class="lineNum">     227 </span>                : };
<span class="lineNum">     228 </span>                : 
<span class="lineNum">     229 </span>                : /// Both source and destination ranges are delimited by image iterators
<span class="lineNum">     230 </span>                : template &lt;typename IL, typename OL&gt;
<span class="lineNum">     231 </span>                : struct copier_n&lt;iterator_from_2d&lt;IL&gt;,iterator_from_2d&lt;OL&gt; &gt; {
<span class="lineNum">     232 </span>                :    typedef typename iterator_from_2d&lt;IL&gt;::difference_type diff_t;
<span class="lineNum">     233 </span>                :    GIL_FORCEINLINE void operator()(iterator_from_2d&lt;IL&gt; src, diff_t n, iterator_from_2d&lt;OL&gt; dst) const {
<span class="lineNum">     234 </span>                :         gil_function_requires&lt;PixelLocatorConcept&lt;IL&gt; &gt;();
<span class="lineNum">     235 </span>                :         gil_function_requires&lt;MutablePixelLocatorConcept&lt;OL&gt; &gt;();
<span class="lineNum">     236 </span>                :         if (src.x_pos()!=dst.x_pos() || src.width()!=dst.width()) {
<span class="lineNum">     237 </span>                :             while(n--&gt;0) {
<span class="lineNum">     238 </span>                :                 *dst++=*src++;
<span class="lineNum">     239 </span>                :             }
<span class="lineNum">     240 </span>                :         }
<span class="lineNum">     241 </span>                :         while (n&gt;0) {
<span class="lineNum">     242 </span>                :             diff_t l=dst.width()-dst.x_pos();
<span class="lineNum">     243 </span>                :             diff_t numToCopy=(n&lt;l ? n : l);
<span class="lineNum">     244 </span>                :             detail::copy_n(src.x(), numToCopy, dst.x());
<span class="lineNum">     245 </span>                :             dst+=numToCopy;
<span class="lineNum">     246 </span>                :             src+=numToCopy;
<span class="lineNum">     247 </span>                :             n-=numToCopy;
<span class="lineNum">     248 </span>                :         }
<span class="lineNum">     249 </span>                :     }
<span class="lineNum">     250 </span>                : };
<span class="lineNum">     251 </span>                : 
<span class="lineNum">     252 </span>                : template &lt;typename SrcIterator, typename DstIterator&gt;
<span class="lineNum">     253 </span>                : GIL_FORCEINLINE DstIterator copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) {
<span class="lineNum">     254 </span>                :     typedef typename SrcIterator::x_iterator src_x_iterator;
<span class="lineNum">     255 </span>                :     typedef typename DstIterator::x_iterator dst_x_iterator;
<span class="lineNum">     256 </span>                : 
<span class="lineNum">     257 </span>                :     typename SrcIterator::difference_type n = last - first;
<span class="lineNum">     258 </span>                : 
<span class="lineNum">     259 </span>                :     if (first.is_1d_traversable()) {
<span class="lineNum">     260 </span>                :         if (dst.is_1d_traversable())
<span class="lineNum">     261 </span>                :             copier_n&lt;src_x_iterator,dst_x_iterator&gt;()(first.x(),n, dst.x());
<span class="lineNum">     262 </span>                :         else
<span class="lineNum">     263 </span>                :             copier_n&lt;src_x_iterator,DstIterator &gt;()(first.x(),n, dst);
<span class="lineNum">     264 </span>                :     } else {
<span class="lineNum">     265 </span>                :         if (dst.is_1d_traversable())
<span class="lineNum">     266 </span>                :             copier_n&lt;SrcIterator,dst_x_iterator&gt;()(first,n, dst.x());
<span class="lineNum">     267 </span>                :         else
<span class="lineNum">     268 </span>                :             copier_n&lt;SrcIterator,DstIterator&gt;()(first,n,dst);
<span class="lineNum">     269 </span>                :     }
<span class="lineNum">     270 </span>                :     return dst+n;
<span class="lineNum">     271 </span>                : }
<span class="lineNum">     272 </span>                : 
<span class="lineNum">     273 </span>                : } // namespace detail
<span class="lineNum">     274 </span>                : } }  // namespace boost::gil
<span class="lineNum">     275 </span>                : 
<span class="lineNum">     276 </span>                : namespace std {
<span class="lineNum">     277 </span>                : /// \ingroup STLOptimizations
<span class="lineNum">     278 </span>                : /// \brief  std::copy(I1,I1,I2) with I1 and I2 being a iterator_from_2d
<span class="lineNum">     279 </span>                : template &lt;typename IL, typename OL&gt;
<span class="lineNum">     280 </span>                : GIL_FORCEINLINE boost::gil::iterator_from_2d&lt;OL&gt; copy1(boost::gil::iterator_from_2d&lt;IL&gt; first, boost::gil::iterator_from_2d&lt;IL&gt; last, boost::gil::iterator_from_2d&lt;OL&gt; dst) {
<span class="lineNum">     281 </span>                :     return boost::gil::detail::copy_with_2d_iterators(first,last,dst);
<span class="lineNum">     282 </span>                : }
<span class="lineNum">     283 </span>                : 
<span class="lineNum">     284 </span>                : } // namespace std
<span class="lineNum">     285 </span>                : 
<span class="lineNum">     286 </span>                : namespace boost { namespace gil {
<span class="lineNum">     287 </span>                : 
<span class="lineNum">     288 </span>                : 
<span class="lineNum">     289 </span>                : /// \ingroup ImageViewSTLAlgorithmsCopyPixels
<span class="lineNum">     290 </span>                : /// \brief std::copy for image views
<span class="lineNum">     291 </span>                : template &lt;typename View1, typename View2&gt; GIL_FORCEINLINE
<span class="lineNum">     292 </span>                : void copy_pixels(const View1&amp; src, const View2&amp; dst) { 
<span class="lineNum">     293 </span>                :     assert(src.dimensions()==dst.dimensions());
<span class="lineNum">     294 </span>                :     detail::copy_with_2d_iterators(src.begin(),src.end(),dst.begin());
<span class="lineNum">     295 </span>                : }
<span class="lineNum">     296 </span>                : 
<span class="lineNum">     297 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     298 </span>                : ///
<span class="lineNum">     299 </span>                : /// copy_and_convert_pixels
<span class="lineNum">     300 </span>                : ///
<span class="lineNum">     301 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     302 </span>                : 
<span class="lineNum">     303 </span>                : /// \defgroup ImageViewSTLAlgorithmsCopyAndConvertPixels copy_and_convert_pixels
<span class="lineNum">     304 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     305 </span>                : /// \brief copies src view into dst view, color converting if necessary.
<span class="lineNum">     306 </span>                : ///
<span class="lineNum">     307 </span>                : /// Versions taking static and runtime views are provided. Versions taking user-defined color convered are provided.
<span class="lineNum">     308 </span>                : 
<span class="lineNum">     309 </span>                : namespace detail {
<span class="lineNum">     310 </span>                : template &lt;typename CC&gt;
<span class="lineNum">     311 </span>                : class copy_and_convert_pixels_fn : public binary_operation_obj&lt;copy_and_convert_pixels_fn&lt;CC&gt; &gt; {
<span class="lineNum">     312 </span>                : private:
<span class="lineNum">     313 </span>                :     CC _cc;
<span class="lineNum">     314 </span>                : public:
<span class="lineNum">     315 </span>                :     typedef typename binary_operation_obj&lt;copy_and_convert_pixels_fn&lt;CC&gt; &gt;::result_type result_type;
<span class="lineNum">     316 </span>                :     copy_and_convert_pixels_fn() {}
<span class="lineNum">     317 </span>                :     copy_and_convert_pixels_fn(CC cc_in) : _cc(cc_in) {}
<span class="lineNum">     318 </span>                :    // when the two color spaces are incompatible, a color conversion is performed
<span class="lineNum">     319 </span>                :     template &lt;typename V1, typename V2&gt; GIL_FORCEINLINE 
<span class="lineNum">     320 </span>                :     result_type apply_incompatible(const V1&amp; src, const V2&amp; dst) const {
<span class="lineNum">     321 </span>                :         copy_pixels(color_converted_view&lt;typename V2::value_type&gt;(src,_cc),dst);
<span class="lineNum">     322 </span>                :     }
<span class="lineNum">     323 </span>                : 
<span class="lineNum">     324 </span>                :     // If the two color spaces are compatible, copy_and_convert is just copy
<span class="lineNum">     325 </span>                :     template &lt;typename V1, typename V2&gt; GIL_FORCEINLINE 
<span class="lineNum">     326 </span>                :     result_type apply_compatible(const V1&amp; src, const V2&amp; dst) const {
<span class="lineNum">     327 </span>                :          copy_pixels(src,dst);
<span class="lineNum">     328 </span>                :     }
<span class="lineNum">     329 </span>                : };
<span class="lineNum">     330 </span>                : } // namespace detail
<span class="lineNum">     331 </span>                : 
<span class="lineNum">     332 </span>                : /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
<span class="lineNum">     333 </span>                : template &lt;typename V1, typename V2,typename CC&gt; 
<span class="lineNum">     334 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     335 </span>                : void copy_and_convert_pixels(const V1&amp; src, const V2&amp; dst,CC cc) { 
<span class="lineNum">     336 </span>                :     detail::copy_and_convert_pixels_fn&lt;CC&gt; ccp(cc);
<span class="lineNum">     337 </span>                :     ccp(src,dst);
<span class="lineNum">     338 </span>                : }
<span class="lineNum">     339 </span>                : 
<span class="lineNum">     340 </span>                : struct default_color_converter;
<span class="lineNum">     341 </span>                : 
<span class="lineNum">     342 </span>                : /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
<span class="lineNum">     343 </span>                : template &lt;typename View1, typename View2&gt; 
<span class="lineNum">     344 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     345 </span>                : void copy_and_convert_pixels(const View1&amp; src, const View2&amp; dst) { 
<span class="lineNum">     346 </span>                :     detail::copy_and_convert_pixels_fn&lt;default_color_converter&gt; ccp;
<span class="lineNum">     347 </span>                :     ccp(src,dst);
<span class="lineNum">     348 </span>                : }
<span class="lineNum">     349 </span>                : 
<span class="lineNum">     350 </span>                : } }  // namespace boost::gil
<span class="lineNum">     351 </span>                : 
<span class="lineNum">     352 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     353 </span>                : //
<span class="lineNum">     354 </span>                : // std::fill and gil::fill_pixels
<span class="lineNum">     355 </span>                : //
<span class="lineNum">     356 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     357 </span>                : 
<span class="lineNum">     358 </span>                : /// \defgroup ImageViewSTLAlgorithmsFillPixels fill_pixels
<span class="lineNum">     359 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     360 </span>                : /// \brief std::fill for image views
<span class="lineNum">     361 </span>                : 
<span class="lineNum">     362 </span>                : 
<span class="lineNum">     363 </span>                : namespace std {
<span class="lineNum">     364 </span>                : /// \ingroup STLOptimizations
<span class="lineNum">     365 </span>                : /// \brief std::fill(I,I,V) with I being a iterator_from_2d
<span class="lineNum">     366 </span>                : ///
<span class="lineNum">     367 </span>                : /// Invoked when one calls std::fill(I,I,V) with I being a iterator_from_2d (which is
<span class="lineNum">     368 </span>                : /// a 1D iterator over the pixels in an image). For contiguous images (i.e. images that have
<span class="lineNum">     369 </span>                : /// no alignment gap at the end of each row) it is more efficient to use the underlying 
<span class="lineNum">     370 </span>                : /// pixel iterator that does not check for the end of rows. For non-contiguous images fill
<span class="lineNum">     371 </span>                : /// resolves to fill of each row using the underlying pixel iterator, which is still faster
<span class="lineNum">     372 </span>                : template &lt;typename IL, typename V&gt;
<span class="lineNum">     373 </span>                : void fill(boost::gil::iterator_from_2d&lt;IL&gt; first, boost::gil::iterator_from_2d&lt;IL&gt; last, const V&amp; val) {
<span class="lineNum">     374 </span>                :     boost::gil::gil_function_requires&lt;boost::gil::MutablePixelLocatorConcept&lt;IL&gt; &gt;();
<span class="lineNum">     375 </span>                :     if (first.is_1d_traversable()) {
<span class="lineNum">     376 </span>                :         std::fill(first.x(), last.x(), val);
<span class="lineNum">     377 </span>                :     } else {
<span class="lineNum">     378 </span>                :         // fill row by row
<span class="lineNum">     379 </span>                :         std::ptrdiff_t n=last-first;
<span class="lineNum">     380 </span>                :         while (n&gt;0) {
<span class="lineNum">     381 </span>                :             std::ptrdiff_t numToDo=std::min&lt;const std::ptrdiff_t&gt;(n,(std::ptrdiff_t)(first.width()-first.x_pos()));
<span class="lineNum">     382 </span>                :             fill_n(first.x(), numToDo, val);
<span class="lineNum">     383 </span>                :             first+=numToDo;
<span class="lineNum">     384 </span>                :             n-=numToDo;
<span class="lineNum">     385 </span>                :         }
<span class="lineNum">     386 </span>                :     }
<span class="lineNum">     387 </span>                : } 
<span class="lineNum">     388 </span>                : } // namespace std
<span class="lineNum">     389 </span>                : 
<span class="lineNum">     390 </span>                : namespace boost { namespace gil {
<span class="lineNum">     391 </span>                : 
<span class="lineNum">     392 </span>                : namespace detail {
<span class="lineNum">     393 </span>                : /// struct to do std::fill
<span class="lineNum">     394 </span>                : struct std_fill_t {
<span class="lineNum">     395 </span>                :     template &lt;typename It, typename P&gt;
<span class="lineNum">     396 </span>                :     void operator()(It first, It last, const P&amp; p_in) {
<span class="lineNum">     397 </span>                :         std::fill(first,last,p_in);
<span class="lineNum">     398 </span>                :     }
<span class="lineNum">     399 </span>                : };
<span class="lineNum">     400 </span>                : /// std::fill for planar iterators
<span class="lineNum">     401 </span>                : template &lt;typename It, typename P&gt;
<span class="lineNum">     402 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     403 </span>                : void fill_aux(It first, It last, const P&amp; p, mpl::true_) {
<span class="lineNum">     404 </span>                :     static_for_each(first,last,p,std_fill_t());
<span class="lineNum">     405 </span>                : }
<span class="lineNum">     406 </span>                : /// std::fill for interleaved iterators
<span class="lineNum">     407 </span>                : template &lt;typename It, typename P&gt;
<span class="lineNum">     408 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     409 </span>                : void fill_aux(It first, It last, const P&amp; p,mpl::false_) {
<span class="lineNum">     410 </span>                :     std::fill(first,last,p);
<span class="lineNum">     411 </span>                : }
<span class="lineNum">     412 </span>                : } // namespace detail
<span class="lineNum">     413 </span>                : 
<span class="lineNum">     414 </span>                : /// \ingroup ImageViewSTLAlgorithmsFillPixels
<span class="lineNum">     415 </span>                : /// \brief std::fill for image views
<span class="lineNum">     416 </span>                : template &lt;typename View, typename Value&gt; GIL_FORCEINLINE 
<span class="lineNum">     417 </span>                : void fill_pixels(const View&amp; img_view, const Value&amp; val) {
<span class="lineNum">     418 </span>                :     if (img_view.is_1d_traversable())
<span class="lineNum">     419 </span>                :         detail::fill_aux(img_view.begin().x(), img_view.end().x(), 
<span class="lineNum">     420 </span>                :                  val,is_planar&lt;View&gt;());
<span class="lineNum">     421 </span>                :     else
<span class="lineNum">     422 </span>                :         for (std::ptrdiff_t y=0; y&lt;img_view.height(); ++y)
<span class="lineNum">     423 </span>                :             detail::fill_aux(img_view.row_begin(y),img_view.row_end(y),
<span class="lineNum">     424 </span>                :                      val,is_planar&lt;View&gt;());
<span class="lineNum">     425 </span>                : }
<span class="lineNum">     426 </span>                : 
<span class="lineNum">     427 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     428 </span>                : ///
<span class="lineNum">     429 </span>                : /// destruct_pixels
<span class="lineNum">     430 </span>                : ///
<span class="lineNum">     431 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     432 </span>                : 
<span class="lineNum">     433 </span>                : /// \defgroup ImageViewSTLAlgorithmsDestructPixels destruct_pixels
<span class="lineNum">     434 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     435 </span>                : /// \brief invokes the destructor on every pixel of an image view
<span class="lineNum">     436 </span>                : 
<span class="lineNum">     437 </span>                : 
<span class="lineNum">     438 </span>                : namespace detail {
<span class="lineNum">     439 </span>                : 
<span class="lineNum">     440 </span>                : template &lt;typename It&gt; GIL_FORCEINLINE
<span class="lineNum">     441 </span><span class="lineCov">              7 : void destruct_range_impl(It first, It last, mpl::true_) {</span>
<span class="lineNum">     442 </span>                :     typedef typename std::iterator_traits&lt;It&gt;::value_type value_t;
<span class="lineNum">     443 </span>                :     if (boost::has_trivial_destructor&lt;value_t&gt;::value)
<span class="lineNum">     444 </span>                :         return;
<span class="lineNum">     445 </span>                :     while (first!=last) {
<span class="lineNum">     446 </span>                :         first-&gt;~value_t();
<span class="lineNum">     447 </span>                :         ++first;
<span class="lineNum">     448 </span>                :     }
<span class="lineNum">     449 </span>                : }
<span class="lineNum">     450 </span>                : template &lt;typename It&gt; GIL_FORCEINLINE
<span class="lineNum">     451 </span>                : void destruct_range_impl(It first, It last, mpl::false_) {}
<span class="lineNum">     452 </span>                : 
<span class="lineNum">     453 </span>                : template &lt;typename It&gt; GIL_FORCEINLINE
<span class="lineNum">     454 </span><span class="lineCov">              7 : void destruct_range(It first, It last) {</span>
<span class="lineNum">     455 </span><span class="lineCov">              7 :     destruct_range_impl(first,last,typename is_pointer&lt;It&gt;::type());</span>
<span class="lineNum">     456 </span><span class="lineCov">              7 : }</span>
<span class="lineNum">     457 </span>                : 
<span class="lineNum">     458 </span>                : struct std_destruct_t {
<span class="lineNum">     459 </span>                :     template &lt;typename It&gt; void operator()(It first, It last) const { destruct_range(first,last); }
<span class="lineNum">     460 </span>                : };
<span class="lineNum">     461 </span>                : 
<span class="lineNum">     462 </span>                : /// destruct for planar iterators
<span class="lineNum">     463 </span>                : template &lt;typename It&gt;
<span class="lineNum">     464 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     465 </span>                : void destruct_aux(It first, It last, mpl::true_) {
<span class="lineNum">     466 </span>                :     static_for_each(first,last,std_destruct_t());
<span class="lineNum">     467 </span>                : }
<span class="lineNum">     468 </span>                : /// destruct for interleaved iterators
<span class="lineNum">     469 </span>                : template &lt;typename It&gt;
<span class="lineNum">     470 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     471 </span><span class="lineCov">              7 : void destruct_aux(It first, It last, mpl::false_) {</span>
<span class="lineNum">     472 </span><span class="lineCov">              7 :     destruct_range(first,last);</span>
<span class="lineNum">     473 </span><span class="lineCov">              7 : }</span>
<span class="lineNum">     474 </span>                : 
<span class="lineNum">     475 </span>                : } // namespace detail
<span class="lineNum">     476 </span>                : 
<span class="lineNum">     477 </span>                : /// \ingroup ImageViewSTLAlgorithmsDestructPixels
<span class="lineNum">     478 </span>                : /// \brief Invokes the in-place destructor on every pixel of the view
<span class="lineNum">     479 </span>                : template &lt;typename View&gt; GIL_FORCEINLINE 
<span class="lineNum">     480 </span><span class="lineCov">             15 : void destruct_pixels(const View&amp; img_view) {</span>
<span class="lineNum">     481 </span><span class="lineCov">             15 :     if (img_view.is_1d_traversable()) </span>
<span class="lineNum">     482 </span><span class="lineCov">              7 :         detail::destruct_aux(img_view.begin().x(), img_view.end().x(), </span>
<span class="lineNum">     483 </span>                :                                        is_planar&lt;View&gt;());
<span class="lineNum">     484 </span>                :     else
<span class="lineNum">     485 </span><span class="lineCov">              8 :         for (std::ptrdiff_t y=0; y&lt;img_view.height(); ++y)</span>
<span class="lineNum">     486 </span><span class="lineNoCov">              0 :             detail::destruct_aux(img_view.row_begin(y),img_view.row_end(y),</span>
<span class="lineNum">     487 </span>                :                                            is_planar&lt;View&gt;());
<span class="lineNum">     488 </span><span class="lineCov">             15 : }</span>
<span class="lineNum">     489 </span>                : 
<span class="lineNum">     490 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     491 </span>                : ///
<span class="lineNum">     492 </span>                : /// uninitialized_fill_pixels
<span class="lineNum">     493 </span>                : ///
<span class="lineNum">     494 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     495 </span>                : 
<span class="lineNum">     496 </span>                : /// \defgroup ImageViewSTLAlgorithmsUninitializedFillPixels uninitialized_fill_pixels
<span class="lineNum">     497 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     498 </span>                : /// \brief std::uninitialized_fill for image views
<span class="lineNum">     499 </span>                : 
<span class="lineNum">     500 </span>                : 
<span class="lineNum">     501 </span>                : namespace detail {
<span class="lineNum">     502 </span>                : 
<span class="lineNum">     503 </span>                : /// std::uninitialized_fill for planar iterators
<span class="lineNum">     504 </span>                : /// If an exception is thrown destructs any in-place copy-constructed objects
<span class="lineNum">     505 </span>                : template &lt;typename It, typename P&gt;
<span class="lineNum">     506 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     507 </span>                : void uninitialized_fill_aux(It first, It last,
<span class="lineNum">     508 </span>                :                             const P&amp; p, mpl::true_) {
<span class="lineNum">     509 </span>                :     int channel=0;
<span class="lineNum">     510 </span>                :     try {
<span class="lineNum">     511 </span>                :         typedef typename std::iterator_traits&lt;It&gt;::value_type pixel_t;
<span class="lineNum">     512 </span>                :         while (channel &lt; num_channels&lt;pixel_t&gt;::value) {
<span class="lineNum">     513 </span>                :             std::uninitialized_fill(dynamic_at_c(first,channel), dynamic_at_c(last,channel), 
<span class="lineNum">     514 </span>                :                                     dynamic_at_c(p,channel));
<span class="lineNum">     515 </span>                :             ++channel;
<span class="lineNum">     516 </span>                :         }
<span class="lineNum">     517 </span>                :     } catch (...) {
<span class="lineNum">     518 </span>                :         for (int c=0; c&lt;channel; ++c)
<span class="lineNum">     519 </span>                :             destruct_range(dynamic_at_c(first,c), dynamic_at_c(last,c));
<span class="lineNum">     520 </span>                :         throw;
<span class="lineNum">     521 </span>                :     }
<span class="lineNum">     522 </span>                : }
<span class="lineNum">     523 </span>                : 
<span class="lineNum">     524 </span>                : /// std::uninitialized_fill for interleaved iterators
<span class="lineNum">     525 </span>                : /// If an exception is thrown destructs any in-place copy-constructed objects
<span class="lineNum">     526 </span>                : template &lt;typename It, typename P&gt;
<span class="lineNum">     527 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     528 </span>                : void uninitialized_fill_aux(It first, It last,
<span class="lineNum">     529 </span>                :                             const P&amp; p,mpl::false_) {
<span class="lineNum">     530 </span>                :     std::uninitialized_fill(first,last,p);
<span class="lineNum">     531 </span>                : }
<span class="lineNum">     532 </span>                : 
<span class="lineNum">     533 </span>                : } // namespace detail
<span class="lineNum">     534 </span>                : 
<span class="lineNum">     535 </span>                : /// \ingroup ImageViewSTLAlgorithmsUninitializedFillPixels
<span class="lineNum">     536 </span>                : /// \brief std::uninitialized_fill for image views.
<span class="lineNum">     537 </span>                : /// Does not support planar heterogeneous views.
<span class="lineNum">     538 </span>                : /// If an exception is thrown destructs any in-place copy-constructed pixels
<span class="lineNum">     539 </span>                : template &lt;typename View, typename Value&gt; 
<span class="lineNum">     540 </span>                : void uninitialized_fill_pixels(const View&amp; img_view, const Value&amp; val) {
<span class="lineNum">     541 </span>                :     if (img_view.is_1d_traversable()) 
<span class="lineNum">     542 </span>                :         detail::uninitialized_fill_aux(img_view.begin().x(), img_view.end().x(), 
<span class="lineNum">     543 </span>                :                                        val,is_planar&lt;View&gt;());
<span class="lineNum">     544 </span>                :     else {
<span class="lineNum">     545 </span>                :         typename View::y_coord_t y;
<span class="lineNum">     546 </span>                :         try {
<span class="lineNum">     547 </span>                :             for (y=0; y&lt;img_view.height(); ++y)
<span class="lineNum">     548 </span>                :                 detail::uninitialized_fill_aux(img_view.row_begin(y),img_view.row_end(y),
<span class="lineNum">     549 </span>                :                                                val,is_planar&lt;View&gt;());
<span class="lineNum">     550 </span>                :         } catch(...) {
<span class="lineNum">     551 </span>                :             for (typename View::y_coord_t y0=0; y0&lt;y; ++y0)
<span class="lineNum">     552 </span>                :                 detail::destruct_aux(img_view.row_begin(y0),img_view.row_end(y0), is_planar&lt;View&gt;());
<span class="lineNum">     553 </span>                :             throw;
<span class="lineNum">     554 </span>                :         }
<span class="lineNum">     555 </span>                :     }
<span class="lineNum">     556 </span>                : }
<span class="lineNum">     557 </span>                : 
<span class="lineNum">     558 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     559 </span>                : ///
<span class="lineNum">     560 </span>                : /// default_construct_pixels
<span class="lineNum">     561 </span>                : ///
<span class="lineNum">     562 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     563 </span>                : 
<span class="lineNum">     564 </span>                : /// \defgroup ImageViewSTLAlgorithmsDefaultConstructPixels default_construct_pixels
<span class="lineNum">     565 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     566 </span>                : /// \brief invokes the default constructor on every pixel of an image view
<span class="lineNum">     567 </span>                : 
<span class="lineNum">     568 </span>                : namespace detail {
<span class="lineNum">     569 </span>                : 
<span class="lineNum">     570 </span>                : template &lt;typename It&gt; GIL_FORCEINLINE 
<span class="lineNum">     571 </span>                : void default_construct_range_impl(It first, It last, mpl::true_) {
<span class="lineNum">     572 </span>                :     typedef typename std::iterator_traits&lt;It&gt;::value_type value_t;
<span class="lineNum">     573 </span>                :     It first1=first;
<span class="lineNum">     574 </span>                :     try {
<span class="lineNum">     575 </span>                :         while (first!=last) {
<span class="lineNum">     576 </span>                :             new (first) value_t();
<span class="lineNum">     577 </span>                :             ++first;
<span class="lineNum">     578 </span>                :         }
<span class="lineNum">     579 </span>                :     } catch (...) {
<span class="lineNum">     580 </span>                :         destruct_range(first1,first);
<span class="lineNum">     581 </span>                :         throw;
<span class="lineNum">     582 </span>                :     }
<span class="lineNum">     583 </span>                : }
<span class="lineNum">     584 </span>                : 
<span class="lineNum">     585 </span>                : template &lt;typename It&gt; GIL_FORCEINLINE 
<span class="lineNum">     586 </span>                : void default_construct_range_impl(It first, It last, mpl::false_) {}
<span class="lineNum">     587 </span>                : 
<span class="lineNum">     588 </span>                : template &lt;typename It&gt; GIL_FORCEINLINE 
<span class="lineNum">     589 </span>                : void default_construct_range(It first, It last) { default_construct_range_impl(first, last, typename is_pointer&lt;It&gt;::type()); }
<span class="lineNum">     590 </span>                : 
<span class="lineNum">     591 </span>                : /// uninitialized_default_construct for planar iterators
<span class="lineNum">     592 </span>                : template &lt;typename It&gt;
<span class="lineNum">     593 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     594 </span>                : void default_construct_aux(It first, It last, mpl::true_) {
<span class="lineNum">     595 </span>                :     int channel=0;
<span class="lineNum">     596 </span>                :     try {
<span class="lineNum">     597 </span>                :         typedef typename std::iterator_traits&lt;It&gt;::value_type pixel_t;
<span class="lineNum">     598 </span>                :         while (channel &lt; num_channels&lt;pixel_t&gt;::value) {
<span class="lineNum">     599 </span>                :             default_construct_range(dynamic_at_c(first,channel), dynamic_at_c(last,channel));
<span class="lineNum">     600 </span>                :             ++channel;
<span class="lineNum">     601 </span>                :         }
<span class="lineNum">     602 </span>                :     } catch (...) {
<span class="lineNum">     603 </span>                :         for (int c=0; c&lt;channel; ++c)
<span class="lineNum">     604 </span>                :             destruct_range(dynamic_at_c(first,c), dynamic_at_c(last,c));
<span class="lineNum">     605 </span>                :         throw;
<span class="lineNum">     606 </span>                :     }
<span class="lineNum">     607 </span>                : }
<span class="lineNum">     608 </span>                : 
<span class="lineNum">     609 </span>                : /// uninitialized_default_construct for interleaved iterators
<span class="lineNum">     610 </span>                : template &lt;typename It&gt;
<span class="lineNum">     611 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     612 </span>                : void default_construct_aux(It first, It last, mpl::false_) {
<span class="lineNum">     613 </span>                :     default_construct_range(first,last);
<span class="lineNum">     614 </span>                : }
<span class="lineNum">     615 </span>                : 
<span class="lineNum">     616 </span>                : template &lt;typename View, bool IsPlanar&gt;
<span class="lineNum">     617 </span>                : struct has_trivial_pixel_constructor : public boost::has_trivial_constructor&lt;typename View::value_type&gt; {};
<span class="lineNum">     618 </span>                : template &lt;typename View&gt;
<span class="lineNum">     619 </span>                : struct has_trivial_pixel_constructor&lt;View, true&gt; : public boost::has_trivial_constructor&lt;typename channel_type&lt;View&gt;::type&gt; {};
<span class="lineNum">     620 </span>                : 
<span class="lineNum">     621 </span>                : } // namespace detail
<span class="lineNum">     622 </span>                : 
<span class="lineNum">     623 </span>                : /// \ingroup ImageViewSTLAlgorithmsDefaultConstructPixels
<span class="lineNum">     624 </span>                : /// \brief Invokes the in-place default constructor on every pixel of the (uninitialized) view.
<span class="lineNum">     625 </span>                : /// Does not support planar heterogeneous views.
<span class="lineNum">     626 </span>                : /// If an exception is thrown destructs any in-place default-constructed pixels
<span class="lineNum">     627 </span>                : template &lt;typename View&gt; 
<span class="lineNum">     628 </span><span class="lineCov">              7 : void default_construct_pixels(const View&amp; img_view) {</span>
<span class="lineNum">     629 </span>                :     if (detail::has_trivial_pixel_constructor&lt;View, is_planar&lt;View&gt;::value&gt;::value)
<span class="lineNum">     630 </span>                :         return;
<span class="lineNum">     631 </span>                : 
<span class="lineNum">     632 </span>                :     if (img_view.is_1d_traversable()) 
<span class="lineNum">     633 </span>                :         detail::default_construct_aux(img_view.begin().x(), img_view.end().x(), is_planar&lt;View&gt;());
<span class="lineNum">     634 </span>                :     else {
<span class="lineNum">     635 </span>                :         typename View::y_coord_t y;
<span class="lineNum">     636 </span>                :         try {
<span class="lineNum">     637 </span>                :             for (y=0; y&lt;img_view.height(); ++y)
<span class="lineNum">     638 </span>                :                 detail::default_construct_aux(img_view.row_begin(y),img_view.row_end(y), is_planar&lt;View&gt;());
<span class="lineNum">     639 </span>                :         } catch(...) {
<span class="lineNum">     640 </span>                :             for (typename View::y_coord_t y0=0; y0&lt;y; ++y0)
<span class="lineNum">     641 </span>                :                 detail::destruct_aux(img_view.row_begin(y0),img_view.row_end(y0), is_planar&lt;View&gt;());
<span class="lineNum">     642 </span>                :             throw;
<span class="lineNum">     643 </span>                :         }
<span class="lineNum">     644 </span>                :     }
<span class="lineNum">     645 </span>                : }
<span class="lineNum">     646 </span>                : 
<span class="lineNum">     647 </span>                : 
<span class="lineNum">     648 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     649 </span>                : ///
<span class="lineNum">     650 </span>                : /// uninitialized_copy_pixels
<span class="lineNum">     651 </span>                : ///
<span class="lineNum">     652 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     653 </span>                : 
<span class="lineNum">     654 </span>                : /// \defgroup ImageViewSTLAlgorithmsUninitializedCopyPixels uninitialized_copy_pixels
<span class="lineNum">     655 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     656 </span>                : /// \brief std::uninitialized_copy for image views
<span class="lineNum">     657 </span>                : 
<span class="lineNum">     658 </span>                : namespace detail {
<span class="lineNum">     659 </span>                : 
<span class="lineNum">     660 </span>                : /// std::uninitialized_copy for pairs of planar iterators
<span class="lineNum">     661 </span>                : template &lt;typename It1, typename It2&gt;
<span class="lineNum">     662 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     663 </span>                : void uninitialized_copy_aux(It1 first1, It1 last1,
<span class="lineNum">     664 </span>                :                             It2 first2, mpl::true_) {
<span class="lineNum">     665 </span>                :     int channel=0;
<span class="lineNum">     666 </span>                :     try {
<span class="lineNum">     667 </span>                :         typedef typename std::iterator_traits&lt;It1&gt;::value_type pixel_t;
<span class="lineNum">     668 </span>                :         while (channel &lt; num_channels&lt;pixel_t&gt;::value) {
<span class="lineNum">     669 </span>                :             std::uninitialized_copy(dynamic_at_c(first1,channel), dynamic_at_c(last1,channel), dynamic_at_c(first2,channel));
<span class="lineNum">     670 </span>                :             ++channel;
<span class="lineNum">     671 </span>                :         }
<span class="lineNum">     672 </span>                :     } catch (...) {
<span class="lineNum">     673 </span>                :         It2 last2=first2;
<span class="lineNum">     674 </span>                :         std::advance(last2, std::distance(first1,last1));
<span class="lineNum">     675 </span>                :         for (int c=0; c&lt;channel; ++c)
<span class="lineNum">     676 </span>                :             destruct_range(dynamic_at_c(first2,c), dynamic_at_c(last2,c));
<span class="lineNum">     677 </span>                :         throw;
<span class="lineNum">     678 </span>                :     }
<span class="lineNum">     679 </span>                : }
<span class="lineNum">     680 </span>                : /// std::uninitialized_copy for interleaved or mixed iterators
<span class="lineNum">     681 </span>                : template &lt;typename It1, typename It2&gt;
<span class="lineNum">     682 </span>                : GIL_FORCEINLINE 
<span class="lineNum">     683 </span>                : void uninitialized_copy_aux(It1 first1, It1 last1,
<span class="lineNum">     684 </span>                :                             It2 first2,mpl::false_) {
<span class="lineNum">     685 </span>                :     std::uninitialized_copy(first1,last1,first2);
<span class="lineNum">     686 </span>                : }
<span class="lineNum">     687 </span>                : } // namespace detail
<span class="lineNum">     688 </span>                : 
<span class="lineNum">     689 </span>                : /// \ingroup ImageViewSTLAlgorithmsUninitializedCopyPixels
<span class="lineNum">     690 </span>                : /// \brief std::uninitialized_copy for image views.
<span class="lineNum">     691 </span>                : /// Does not support planar heterogeneous views.
<span class="lineNum">     692 </span>                : /// If an exception is thrown destructs any in-place copy-constructed objects
<span class="lineNum">     693 </span>                : template &lt;typename View1, typename View2&gt; 
<span class="lineNum">     694 </span>                : void uninitialized_copy_pixels(const View1&amp; view1, const View2&amp; view2) {
<span class="lineNum">     695 </span>                :     typedef mpl::bool_&lt;is_planar&lt;View1&gt;::value &amp;&amp; is_planar&lt;View2&gt;::value&gt; is_planar;  
<span class="lineNum">     696 </span>                :     assert(view1.dimensions()==view2.dimensions());
<span class="lineNum">     697 </span>                :     if (view1.is_1d_traversable() &amp;&amp; view2.is_1d_traversable())
<span class="lineNum">     698 </span>                :         detail::uninitialized_copy_aux(view1.begin().x(), view1.end().x(), 
<span class="lineNum">     699 </span>                :                                        view2.begin().x(), 
<span class="lineNum">     700 </span>                :                                        is_planar());
<span class="lineNum">     701 </span>                :     else {
<span class="lineNum">     702 </span>                :         typename View1::y_coord_t y;
<span class="lineNum">     703 </span>                :         try {
<span class="lineNum">     704 </span>                :             for (y=0; y&lt;view1.height(); ++y)
<span class="lineNum">     705 </span>                :                 detail::uninitialized_copy_aux(view1.row_begin(y), view1.row_end(y),
<span class="lineNum">     706 </span>                :                                                view2.row_begin(y),
<span class="lineNum">     707 </span>                :                                                is_planar());
<span class="lineNum">     708 </span>                :         } catch(...) {
<span class="lineNum">     709 </span>                :             for (typename View1::y_coord_t y0=0; y0&lt;y; ++y0)
<span class="lineNum">     710 </span>                :                 detail::destruct_aux(view2.row_begin(y0),view2.row_end(y0), is_planar());
<span class="lineNum">     711 </span>                :             throw;
<span class="lineNum">     712 </span>                :         }
<span class="lineNum">     713 </span>                :     }
<span class="lineNum">     714 </span>                : }
<span class="lineNum">     715 </span>                : 
<span class="lineNum">     716 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     717 </span>                : ///
<span class="lineNum">     718 </span>                : /// for_each_pixel
<span class="lineNum">     719 </span>                : ///
<span class="lineNum">     720 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     721 </span>                : 
<span class="lineNum">     722 </span>                : /// \defgroup ImageViewSTLAlgorithmsForEachPixel for_each_pixel
<span class="lineNum">     723 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     724 </span>                : /// \brief std::for_each for image views
<span class="lineNum">     725 </span>                : ///
<span class="lineNum">     726 </span>                : /// For contiguous images (i.e. images that have no alignment gap at the end of each row) it is 
<span class="lineNum">     727 </span>                : /// more efficient to use the underlying pixel iterator that does not check for the end of rows. 
<span class="lineNum">     728 </span>                : /// For non-contiguous images for_each_pixel resolves to for_each of each row using the underlying 
<span class="lineNum">     729 </span>                : /// pixel iterator, which is still faster
<span class="lineNum">     730 </span>                : 
<span class="lineNum">     731 </span>                : /// \ingroup ImageViewSTLAlgorithmsForEachPixel
<span class="lineNum">     732 </span>                : template &lt;typename V, typename F&gt;
<span class="lineNum">     733 </span>                : F for_each_pixel(const V&amp; img, F fun) {
<span class="lineNum">     734 </span>                :     if (img.is_1d_traversable()) {
<span class="lineNum">     735 </span>                :         return std::for_each(img.begin().x(), img.end().x(), fun);
<span class="lineNum">     736 </span>                :     } else {
<span class="lineNum">     737 </span>                :         for (std::ptrdiff_t y=0; y&lt;img.height(); ++y)
<span class="lineNum">     738 </span>                :             fun = std::for_each(img.row_begin(y),img.row_end(y),fun);
<span class="lineNum">     739 </span>                :         return fun;
<span class="lineNum">     740 </span>                :     }
<span class="lineNum">     741 </span>                : }
<span class="lineNum">     742 </span>                : 
<span class="lineNum">     743 </span>                : /// \defgroup ImageViewSTLAlgorithmsForEachPixelPosition for_each_pixel_position
<span class="lineNum">     744 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     745 </span>                : /// \brief adobe::for_each_position for image views (passes locators, instead of pixel references, to the function object)
<span class="lineNum">     746 </span>                : 
<span class="lineNum">     747 </span>                : /// \ingroup ImageViewSTLAlgorithmsForEachPixelPosition
<span class="lineNum">     748 </span>                : template &lt;typename View, typename F&gt;
<span class="lineNum">     749 </span>                : F for_each_pixel_position(const View&amp; img, F fun) {
<span class="lineNum">     750 </span>                :     typename View::xy_locator loc=img.xy_at(0,0);
<span class="lineNum">     751 </span>                :     for (std::ptrdiff_t y=0; y&lt;img.height(); ++y) {
<span class="lineNum">     752 </span>                :         for (std::ptrdiff_t x=0; x&lt;img.width(); ++x, ++loc.x())
<span class="lineNum">     753 </span>                :             fun(loc);
<span class="lineNum">     754 </span>                :         loc.x()-=img.width(); ++loc.y();
<span class="lineNum">     755 </span>                :     }
<span class="lineNum">     756 </span>                :     return fun;
<span class="lineNum">     757 </span>                : }
<span class="lineNum">     758 </span>                : 
<span class="lineNum">     759 </span>                : 
<span class="lineNum">     760 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     761 </span>                : ///
<span class="lineNum">     762 </span>                : /// generate_pixels
<span class="lineNum">     763 </span>                : ///
<span class="lineNum">     764 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     765 </span>                : 
<span class="lineNum">     766 </span>                : /// \defgroup ImageViewSTLAlgorithmsGeneratePixels generate_pixels
<span class="lineNum">     767 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     768 </span>                : /// \brief std::generate for image views
<span class="lineNum">     769 </span>                : 
<span class="lineNum">     770 </span>                : /// \ingroup ImageViewSTLAlgorithmsGeneratePixels
<span class="lineNum">     771 </span>                : /// \brief std::generate for image views
<span class="lineNum">     772 </span>                : template &lt;typename View, typename F&gt;
<span class="lineNum">     773 </span>                : void generate_pixels(const View&amp; v, F fun) {
<span class="lineNum">     774 </span>                :     if (v.is_1d_traversable()) {
<span class="lineNum">     775 </span>                :         std::generate(v.begin().x(), v.end().x(), fun);
<span class="lineNum">     776 </span>                :     } else {
<span class="lineNum">     777 </span>                :         for (std::ptrdiff_t y=0; y&lt;v.height(); ++y)
<span class="lineNum">     778 </span>                :             std::generate(v.row_begin(y),v.row_end(y),fun);
<span class="lineNum">     779 </span>                :     }
<span class="lineNum">     780 </span>                : }
<span class="lineNum">     781 </span>                : 
<span class="lineNum">     782 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     783 </span>                : ///
<span class="lineNum">     784 </span>                : /// std::equal and gil::equal_pixels for GIL constructs
<span class="lineNum">     785 </span>                : ///
<span class="lineNum">     786 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     787 </span>                : 
<span class="lineNum">     788 </span>                : /// \defgroup ImageViewSTLAlgorithmsEqualPixels equal_pixels
<span class="lineNum">     789 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     790 </span>                : /// \brief std::equal for image views
<span class="lineNum">     791 </span>                : 
<span class="lineNum">     792 </span>                : template &lt;typename I1, typename I2&gt; GIL_FORCEINLINE bool equal_n(I1 i1, std::ptrdiff_t n, I2 i2);
<span class="lineNum">     793 </span>                : 
<span class="lineNum">     794 </span>                : namespace detail {
<span class="lineNum">     795 </span>                : 
<span class="lineNum">     796 </span>                : template &lt;typename I1, typename I2&gt;
<span class="lineNum">     797 </span>                : struct equal_n_fn {
<span class="lineNum">     798 </span>                :     GIL_FORCEINLINE bool operator()(I1 i1, std::ptrdiff_t n, I2 i2) const { return std::equal(i1,i1+n, i2); }
<span class="lineNum">     799 </span>                : };
<span class="lineNum">     800 </span>                : 
<span class="lineNum">     801 </span>                : /// Equal when both ranges are interleaved and of the same type. 
<span class="lineNum">     802 </span>                : /// GIL pixels are bitwise comparable, so memcmp is used. User-defined pixels that are not bitwise comparable need to provide an overload
<span class="lineNum">     803 </span>                : template&lt;typename T, typename Cs&gt;
<span class="lineNum">     804 </span>                : struct equal_n_fn&lt;const pixel&lt;T,Cs&gt;*, const pixel&lt;T,Cs&gt;*&gt; {
<span class="lineNum">     805 </span>                :     GIL_FORCEINLINE bool operator()(const pixel&lt;T,Cs&gt;* i1, std::ptrdiff_t n, const pixel&lt;T,Cs&gt;* i2) const { 
<span class="lineNum">     806 </span>                :         return memcmp(i1, i2, n*sizeof(pixel&lt;T,Cs&gt;))==0;
<span class="lineNum">     807 </span>                :     }
<span class="lineNum">     808 </span>                : };
<span class="lineNum">     809 </span>                : template&lt;typename T, typename Cs&gt;
<span class="lineNum">     810 </span>                : struct equal_n_fn&lt;pixel&lt;T,Cs&gt;*, pixel&lt;T,Cs&gt;*&gt; : equal_n_fn&lt;const pixel&lt;T,Cs&gt;*, const pixel&lt;T,Cs&gt;*&gt; {};
<span class="lineNum">     811 </span>                : 
<span class="lineNum">     812 </span>                : /// EqualPixels
<span class="lineNum">     813 </span>                : /// Equal when both ranges are planar pointers of the same type. memcmp is invoked for each channel plane
<span class="lineNum">     814 </span>                : ///  User-defined channels that are not bitwise comparable need to provide an overload
<span class="lineNum">     815 </span>                : template&lt;typename IC, typename Cs&gt;
<span class="lineNum">     816 </span>                : struct equal_n_fn&lt;planar_pixel_iterator&lt;IC,Cs&gt;, planar_pixel_iterator&lt;IC,Cs&gt; &gt; {
<span class="lineNum">     817 </span>                :     GIL_FORCEINLINE bool operator()(const planar_pixel_iterator&lt;IC,Cs&gt; i1, std::ptrdiff_t n, const planar_pixel_iterator&lt;IC,Cs&gt; i2) const { 
<span class="lineNum">     818 </span>                :         ptrdiff_t numBytes=n*sizeof(typename std::iterator_traits&lt;IC&gt;::value_type);
<span class="lineNum">     819 </span>                : 
<span class="lineNum">     820 </span>                :         for (std::ptrdiff_t i=0; i&lt;mpl::size&lt;Cs&gt;::value; ++i)
<span class="lineNum">     821 </span>                :             if (memcmp(dynamic_at_c(i1,i), dynamic_at_c(i2,i), numBytes)!=0)
<span class="lineNum">     822 </span>                :                 return false;
<span class="lineNum">     823 </span>                :         return true;
<span class="lineNum">     824 </span>                :     }
<span class="lineNum">     825 </span>                : };
<span class="lineNum">     826 </span>                : 
<span class="lineNum">     827 </span>                : 
<span class="lineNum">     828 </span>                : /// Source range is delimited by image iterators
<span class="lineNum">     829 </span>                : template &lt;typename Loc, typename I2&gt;  // IL Models ConstPixelLocatorConcept, O Models PixelIteratorConcept
<span class="lineNum">     830 </span>                : struct equal_n_fn&lt;boost::gil::iterator_from_2d&lt;Loc&gt;,I2&gt; {
<span class="lineNum">     831 </span>                :     GIL_FORCEINLINE bool operator()(boost::gil::iterator_from_2d&lt;Loc&gt; i1, std::ptrdiff_t n, I2 i2) const {
<span class="lineNum">     832 </span>                :         gil_function_requires&lt;boost::gil::PixelLocatorConcept&lt;Loc&gt; &gt;();
<span class="lineNum">     833 </span>                :         gil_function_requires&lt;boost::gil::PixelIteratorConcept&lt;I2&gt; &gt;();
<span class="lineNum">     834 </span>                :         while (n&gt;0) {
<span class="lineNum">     835 </span>                :             std::ptrdiff_t num=std::min&lt;const std::ptrdiff_t&gt;(n, i1.width()-i1.x_pos());
<span class="lineNum">     836 </span>                :             if (!equal_n(i1.x(), num, i2))
<span class="lineNum">     837 </span>                :                 return false;
<span class="lineNum">     838 </span>                :             i1+=num;
<span class="lineNum">     839 </span>                :             i2+=num;
<span class="lineNum">     840 </span>                :             n-=num;
<span class="lineNum">     841 </span>                :         }
<span class="lineNum">     842 </span>                :         return true;
<span class="lineNum">     843 </span>                :     }
<span class="lineNum">     844 </span>                : };
<span class="lineNum">     845 </span>                : 
<span class="lineNum">     846 </span>                : /// Destination range is delimited by image iterators
<span class="lineNum">     847 </span>                : template &lt;typename I1, typename Loc&gt; // I Models PixelIteratorConcept, OL Models PixelLocatorConcept
<span class="lineNum">     848 </span>                : struct equal_n_fn&lt;I1,boost::gil::iterator_from_2d&lt;Loc&gt; &gt; {
<span class="lineNum">     849 </span>                :     GIL_FORCEINLINE bool operator()(I1 i1, std::ptrdiff_t n, boost::gil::iterator_from_2d&lt;Loc&gt; i2) const {
<span class="lineNum">     850 </span>                :         gil_function_requires&lt;boost::gil::PixelIteratorConcept&lt;I1&gt; &gt;();
<span class="lineNum">     851 </span>                :         gil_function_requires&lt;boost::gil::PixelLocatorConcept&lt;Loc&gt; &gt;();
<span class="lineNum">     852 </span>                :         while (n&gt;0) {
<span class="lineNum">     853 </span>                :             std::ptrdiff_t num=std::min&lt;const std::ptrdiff_t&gt;(n,i2.width()-i2.x_pos());
<span class="lineNum">     854 </span>                :             if (!equal_n(i1, num, i2.x()))
<span class="lineNum">     855 </span>                :                 return false;
<span class="lineNum">     856 </span>                :             i1+=num;
<span class="lineNum">     857 </span>                :             i2+=num;
<span class="lineNum">     858 </span>                :             n-=num;
<span class="lineNum">     859 </span>                :         }
<span class="lineNum">     860 </span>                :         return true;
<span class="lineNum">     861 </span>                :     }
<span class="lineNum">     862 </span>                : };
<span class="lineNum">     863 </span>                : 
<span class="lineNum">     864 </span>                : /// Both source and destination ranges are delimited by image iterators
<span class="lineNum">     865 </span>                : template &lt;typename Loc1, typename Loc2&gt;
<span class="lineNum">     866 </span>                : struct equal_n_fn&lt;boost::gil::iterator_from_2d&lt;Loc1&gt;,boost::gil::iterator_from_2d&lt;Loc2&gt; &gt; {
<span class="lineNum">     867 </span>                :    GIL_FORCEINLINE bool operator()(boost::gil::iterator_from_2d&lt;Loc1&gt; i1, std::ptrdiff_t n, boost::gil::iterator_from_2d&lt;Loc2&gt; i2) const {
<span class="lineNum">     868 </span>                :         gil_function_requires&lt;boost::gil::PixelLocatorConcept&lt;Loc1&gt; &gt;();
<span class="lineNum">     869 </span>                :         gil_function_requires&lt;boost::gil::PixelLocatorConcept&lt;Loc2&gt; &gt;();
<span class="lineNum">     870 </span>                :         if (i1.x_pos()!=i2.x_pos() || i1.width()!=i2.width()) {
<span class="lineNum">     871 </span>                :             while(n--&gt;0) {
<span class="lineNum">     872 </span>                :                 if (*i1++!=*i2++) return false;
<span class="lineNum">     873 </span>                :             }
<span class="lineNum">     874 </span>                :         }
<span class="lineNum">     875 </span>                :         while (n&gt;0) {
<span class="lineNum">     876 </span>                :             std::ptrdiff_t num=std::min&lt;const std::ptrdiff_t&gt;(n,i2.width()-i2.x_pos());
<span class="lineNum">     877 </span>                :             if (!equal_n(i1.x(), num, i2.x()))
<span class="lineNum">     878 </span>                :                 return false;
<span class="lineNum">     879 </span>                :             i1+=num;
<span class="lineNum">     880 </span>                :             i2+=num;
<span class="lineNum">     881 </span>                :             n-=num;
<span class="lineNum">     882 </span>                :         }
<span class="lineNum">     883 </span>                :         return true;
<span class="lineNum">     884 </span>                :     }
<span class="lineNum">     885 </span>                : };
<span class="lineNum">     886 </span>                : } // namespace detail
<span class="lineNum">     887 </span>                : 
<span class="lineNum">     888 </span>                : template &lt;typename I1, typename I2&gt; GIL_FORCEINLINE
<span class="lineNum">     889 </span>                : bool equal_n(I1 i1, std::ptrdiff_t n, I2 i2) {
<span class="lineNum">     890 </span>                :     return detail::equal_n_fn&lt;I1,I2&gt;()(i1,n,i2);
<span class="lineNum">     891 </span>                : }
<span class="lineNum">     892 </span>                : } }  // namespace boost::gil
<span class="lineNum">     893 </span>                : 
<span class="lineNum">     894 </span>                : namespace std {
<span class="lineNum">     895 </span>                : /// \ingroup STLOptimizations
<span class="lineNum">     896 </span>                : /// \brief  std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
<span class="lineNum">     897 </span>                : ///
<span class="lineNum">     898 </span>                : /// Invoked when one calls std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d (which is
<span class="lineNum">     899 </span>                : /// a 1D iterator over the pixels in an image). Attempts to demote the source and destination 
<span class="lineNum">     900 </span>                : /// iterators to simpler/faster types if the corresponding range is contiguous.
<span class="lineNum">     901 </span>                : /// For contiguous images (i.e. images that have
<span class="lineNum">     902 </span>                : /// no alignment gap at the end of each row) it is more efficient to use the underlying 
<span class="lineNum">     903 </span>                : /// pixel iterator that does not check for the end of rows. If the underlying pixel iterator
<span class="lineNum">     904 </span>                : /// happens to be a fundamental planar/interleaved pointer, the call may further resolve
<span class="lineNum">     905 </span>                : /// to memcmp. Otherwise it resolves to copying each row using the underlying pixel iterator
<span class="lineNum">     906 </span>                : template &lt;typename Loc1, typename Loc2&gt; GIL_FORCEINLINE 
<span class="lineNum">     907 </span>                : bool equal(boost::gil::iterator_from_2d&lt;Loc1&gt; first, boost::gil::iterator_from_2d&lt;Loc1&gt; last, boost::gil::iterator_from_2d&lt;Loc2&gt; first2) {
<span class="lineNum">     908 </span>                :     boost::gil::gil_function_requires&lt;boost::gil::PixelLocatorConcept&lt;Loc1&gt; &gt;();
<span class="lineNum">     909 </span>                :     boost::gil::gil_function_requires&lt;boost::gil::PixelLocatorConcept&lt;Loc2&gt; &gt;();
<span class="lineNum">     910 </span>                :     std::ptrdiff_t n=last-first;
<span class="lineNum">     911 </span>                :     if (first.is_1d_traversable()) {
<span class="lineNum">     912 </span>                :         if (first2.is_1d_traversable())
<span class="lineNum">     913 </span>                :             return boost::gil::detail::equal_n_fn&lt;typename Loc1::x_iterator,typename Loc2::x_iterator&gt;()(first.x(),n, first2.x());
<span class="lineNum">     914 </span>                :         else
<span class="lineNum">     915 </span>                :             return boost::gil::detail::equal_n_fn&lt;typename Loc1::x_iterator,boost::gil::iterator_from_2d&lt;Loc2&gt; &gt;()(first.x(),n, first2);
<span class="lineNum">     916 </span>                :     } else {
<span class="lineNum">     917 </span>                :         if (first2.is_1d_traversable())
<span class="lineNum">     918 </span>                :             return boost::gil::detail::equal_n_fn&lt;boost::gil::iterator_from_2d&lt;Loc1&gt;,typename Loc2::x_iterator&gt;()(first,n, first2.x());
<span class="lineNum">     919 </span>                :         else
<span class="lineNum">     920 </span>                :             return boost::gil::detail::equal_n_fn&lt;boost::gil::iterator_from_2d&lt;Loc1&gt;,boost::gil::iterator_from_2d&lt;Loc2&gt; &gt;()(first,n,first2);
<span class="lineNum">     921 </span>                :     }
<span class="lineNum">     922 </span>                : }
<span class="lineNum">     923 </span>                : } // namespace std
<span class="lineNum">     924 </span>                : 
<span class="lineNum">     925 </span>                : namespace boost { namespace gil {
<span class="lineNum">     926 </span>                : 
<span class="lineNum">     927 </span>                : /// \ingroup ImageViewSTLAlgorithmsEqualPixels
<span class="lineNum">     928 </span>                : /// \brief std::equal for image views
<span class="lineNum">     929 </span>                : template &lt;typename View1, typename View2&gt; GIL_FORCEINLINE 
<span class="lineNum">     930 </span>                : bool equal_pixels(const View1&amp; v1, const View2&amp; v2) {
<span class="lineNum">     931 </span>                :     assert(v1.dimensions()==v2.dimensions());
<span class="lineNum">     932 </span>                :     return std::equal(v1.begin(),v1.end(),v2.begin()); // std::equal has overloads with GIL iterators for optimal performance
<span class="lineNum">     933 </span>                : }
<span class="lineNum">     934 </span>                : 
<span class="lineNum">     935 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     936 </span>                : ///
<span class="lineNum">     937 </span>                : /// transform_pixels
<span class="lineNum">     938 </span>                : ///
<span class="lineNum">     939 </span>                : //////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     940 </span>                : 
<span class="lineNum">     941 </span>                : /// \defgroup ImageViewSTLAlgorithmsTransformPixels transform_pixels
<span class="lineNum">     942 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     943 </span>                : /// \brief std::transform for image views
<span class="lineNum">     944 </span>                : 
<span class="lineNum">     945 </span>                : /// \ingroup ImageViewSTLAlgorithmsTransformPixels
<span class="lineNum">     946 </span>                : /// \brief std::transform for image views
<span class="lineNum">     947 </span>                : template &lt;typename View1, typename View2, typename F&gt; GIL_FORCEINLINE 
<span class="lineNum">     948 </span>                : F transform_pixels(const View1&amp; src,const View2&amp; dst, F fun) {
<span class="lineNum">     949 </span>                :     assert(src.dimensions()==dst.dimensions());
<span class="lineNum">     950 </span>                :     for (std::ptrdiff_t y=0; y&lt;src.height(); ++y) {
<span class="lineNum">     951 </span>                :         typename View1::x_iterator srcIt=src.row_begin(y);
<span class="lineNum">     952 </span>                :         typename View2::x_iterator dstIt=dst.row_begin(y);
<span class="lineNum">     953 </span>                :         for (std::ptrdiff_t x=0; x&lt;src.width(); ++x)
<span class="lineNum">     954 </span>                :             dstIt[x]=fun(srcIt[x]);
<span class="lineNum">     955 </span>                :     }
<span class="lineNum">     956 </span>                :     return fun;
<span class="lineNum">     957 </span>                : }
<span class="lineNum">     958 </span>                : 
<span class="lineNum">     959 </span>                : /// \ingroup ImageViewSTLAlgorithmsTransformPixels
<span class="lineNum">     960 </span>                : /// \brief transform_pixels with two sources
<span class="lineNum">     961 </span>                : template &lt;typename View1, typename View2, typename View3, typename F&gt; GIL_FORCEINLINE 
<span class="lineNum">     962 </span>                : F transform_pixels(const View1&amp; src1, const View2&amp; src2,const View3&amp; dst, F fun) {
<span class="lineNum">     963 </span>                :     for (std::ptrdiff_t y=0; y&lt;dst.height(); ++y) {
<span class="lineNum">     964 </span>                :         typename View1::x_iterator srcIt1=src1.row_begin(y);
<span class="lineNum">     965 </span>                :         typename View2::x_iterator srcIt2=src2.row_begin(y);
<span class="lineNum">     966 </span>                :         typename View3::x_iterator dstIt=dst.row_begin(y);
<span class="lineNum">     967 </span>                :         for (std::ptrdiff_t x=0; x&lt;dst.width(); ++x)
<span class="lineNum">     968 </span>                :             dstIt[x]=fun(srcIt1[x],srcIt2[x]);
<span class="lineNum">     969 </span>                :     }
<span class="lineNum">     970 </span>                :     return fun;
<span class="lineNum">     971 </span>                : }
<span class="lineNum">     972 </span>                : 
<span class="lineNum">     973 </span>                : /// \defgroup ImageViewSTLAlgorithmsTransformPixelPositions transform_pixel_positions
<span class="lineNum">     974 </span>                : /// \ingroup ImageViewSTLAlgorithms
<span class="lineNum">     975 </span>                : /// \brief adobe::transform_positions for image views (passes locators, instead of pixel references, to the function object) 
<span class="lineNum">     976 </span>                : 
<span class="lineNum">     977 </span>                : /// \ingroup ImageViewSTLAlgorithmsTransformPixelPositions
<span class="lineNum">     978 </span>                : /// \brief Like transform_pixels but passes to the function object pixel locators instead of pixel references
<span class="lineNum">     979 </span>                : template &lt;typename View1, typename View2, typename F&gt; GIL_FORCEINLINE 
<span class="lineNum">     980 </span>                : F transform_pixel_positions(const View1&amp; src,const View2&amp; dst, F fun) {
<span class="lineNum">     981 </span>                :     assert(src.dimensions()==dst.dimensions());
<span class="lineNum">     982 </span>                :     typename View1::xy_locator loc=src.xy_at(0,0);
<span class="lineNum">     983 </span>                :     for (std::ptrdiff_t y=0; y&lt;src.height(); ++y) {
<span class="lineNum">     984 </span>                :         typename View2::x_iterator dstIt=dst.row_begin(y);
<span class="lineNum">     985 </span>                :         for (std::ptrdiff_t x=0; x&lt;src.width(); ++x, ++loc.x())
<span class="lineNum">     986 </span>                :             dstIt[x]=fun(loc);
<span class="lineNum">     987 </span>                :         loc.x()-=src.width(); ++loc.y();
<span class="lineNum">     988 </span>                :     }
<span class="lineNum">     989 </span>                :     return fun;
<span class="lineNum">     990 </span>                : }
<span class="lineNum">     991 </span>                : 
<span class="lineNum">     992 </span>                : /// \ingroup ImageViewSTLAlgorithmsTransformPixelPositions
<span class="lineNum">     993 </span>                : /// \brief transform_pixel_positions with two sources
<span class="lineNum">     994 </span>                : template &lt;typename View1, typename View2, typename View3, typename F&gt; GIL_FORCEINLINE 
<span class="lineNum">     995 </span>                : F transform_pixel_positions(const View1&amp; src1,const View2&amp; src2,const View3&amp; dst, F fun) {
<span class="lineNum">     996 </span>                :     assert(src1.dimensions()==dst.dimensions());
<span class="lineNum">     997 </span>                :     assert(src2.dimensions()==dst.dimensions());
<span class="lineNum">     998 </span>                :     typename View1::xy_locator loc1=src1.xy_at(0,0);
<span class="lineNum">     999 </span>                :     typename View2::xy_locator loc2=src2.xy_at(0,0);
<span class="lineNum">    1000 </span>                :     for (std::ptrdiff_t y=0; y&lt;src1.height(); ++y) {
<span class="lineNum">    1001 </span>                :         typename View3::x_iterator dstIt=dst.row_begin(y);
<span class="lineNum">    1002 </span>                :         for (std::ptrdiff_t x=0; x&lt;src1.width(); ++x, ++loc1.x(), ++loc2.x())
<span class="lineNum">    1003 </span>                :             dstIt[x]=fun(loc1,loc2);
<span class="lineNum">    1004 </span>                :         loc1.x()-=src1.width(); ++loc1.y();
<span class="lineNum">    1005 </span>                :         loc2.x()-=src2.width(); ++loc2.y();
<span class="lineNum">    1006 </span>                :     }
<span class="lineNum">    1007 </span>                :     return fun;
<span class="lineNum">    1008 </span>                : }
<span class="lineNum">    1009 </span>                : 
<span class="lineNum">    1010 </span>                : } }  // namespace boost::gil
<span class="lineNum">    1011 </span>                : 
<span class="lineNum">    1012 </span>                : //#ifdef _MSC_VER
<span class="lineNum">    1013 </span>                : //#pragma warning(pop)
<span class="lineNum">    1014 </span>                : //#endif
<span class="lineNum">    1015 </span>                : 
<span class="lineNum">    1016 </span>                : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
